package com.ruoyi.consumer.controller.wallet;

import ch.qos.logback.classic.Logger;
import com.ijpay.core.kit.WxPayKit;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.consumer.domain.*;
import com.ruoyi.consumer.domain.pay.JsApiOrderModel;
import com.ruoyi.consumer.mapper.CWalletCompanyMapper;
import com.ruoyi.consumer.mapper.CWalletPersonMapper;
import com.ruoyi.consumer.service.impl.*;
import com.ruoyi.consumer.utils.JsonUtils;
import com.ruoyi.consumer.utils.pay.OrderNumberGenerator;
import io.jsonwebtoken.lang.Assert;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;

import static com.ruoyi.consumer.utils.JsonUtils.serialize;

@Service
public class WalletServiceImpl implements WalletService {

    private static final Logger logger = (Logger) LoggerFactory.getLogger(JsonUtils.class);
    @Resource
    private WxConfig wxConfig;

    @Resource
    private CDealErrorServiceImpl errorService;

    @Resource
    private CWalletPersonMapper walletPersonMapper;

    @Autowired
    private CUserServiceImpl userService;

    @Autowired
    private CUnitPriceServiceImpl unitPriceService;

    @Autowired
    private WalletServiceImpl walletService;

    @Autowired
    private COrderServiceImpl orderService;

    @Autowired
    private CDealPersonServiceImpl dealPersonService;

    @Autowired
    private CWalletPersonServiceImpl walletPersonService;

    @Autowired
    private CCompanyServiceImpl companyService;

    @Autowired
    private CWalletCompanyServiceImpl walletCompanyService;

    @Autowired
    private CDealCompanyServiceImpl dealCompanyService;

    @Resource
    private CWalletCompanyMapper cWalletCompanyMapper;

    @Autowired
    private RefundService refundService;

    public int updateSign(Map<String, Object> walletInfo) {
        logger.debug("=============进入更新签名=============");
        String walletCheckKey = wxConfig.getWalletCheckKey();
        walletInfo.remove("check_sign");
        String checkSign = encodeHMAC(walletInfo, walletCheckKey);

        CWalletPerson cWalletPerson = new CWalletPerson();
        cWalletPerson.setUserId(Integer.parseInt(walletInfo.get("user_uuid").toString()));
        cWalletPerson.setWalletSign(checkSign);
        logger.debug("=============通过更新签名=============");
        return walletPersonMapper.updateCWalletPerson(cWalletPerson);
    }

    public boolean walletSignCheck(Map<String, Object> walletInfo) {
        String walletCheckKey = wxConfig.getWalletCheckKey();
        boolean check = false;
        String checkSignDB = (String) walletInfo.get("check_sign");
        System.out.println("checkSignDB---------------" + checkSignDB);

        System.out.println("walletInfo-----1" + walletInfo);
        walletInfo.remove("check_sign");
//        walletInfo.remove("update_at");  谁他妈把这写上的
        System.out.println("walletInfo-----2" + walletInfo);
        String checkSign = encodeHMAC(walletInfo, walletCheckKey);
        System.out.println("checkSign---------------" + checkSign);
        System.out.println("签名检查结果" + checkSignDB + "|||" + checkSign);
        if (checkSignDB.equals(checkSign)) {
            check = true;
        } else {
            logger.error("Wallet check sign not match.");
        }
        return check;
    }

    //存入异常表(用户)
    public int saveError(Map<String, Object> walletInfo, CWalletPerson cWalletPersonFirst, CWalletPerson cWalletPersonLater) {
        CDealError cDealError = new CDealError();
        cDealError.setUserId(Integer.parseInt(walletInfo.get("user_uuid").toString()));
        cDealError.setErrorFrom(0);
        cDealError.setDealAmount(Long.parseLong(walletInfo.get("wallet_income").toString()));
        cDealError.setDealType(1);
        cDealError.setDealOriginalJson(JsonUtils.serialize(cWalletPersonFirst));
        cDealError.setDealDisposeJson(JsonUtils.serialize(cWalletPersonLater));
        logger.debug("=============存入异常表通过=============");
        return errorService.insertCDealError(cDealError);
    }

    //存入异常表(公司)
    public int saveErrorCompany(Map<String, Object> walletInfo, CWalletCompany cWalletCompanyFirst, CWalletCompany cWalletCompanyLater) {
        CDealError cDealError = new CDealError();
        cDealError.setUserId(Integer.parseInt(walletInfo.get("user_uuid").toString()));
        cDealError.setErrorFrom(1);
        cDealError.setDealAmount(Long.parseLong(walletInfo.get("wallet_income").toString()));
        cDealError.setDealType(1);
        cDealError.setDealOriginalJson(JsonUtils.serialize(cWalletCompanyFirst));
        cDealError.setDealDisposeJson(JsonUtils.serialize(cWalletCompanyLater));
        logger.debug("=============存入异常表通过=============");
        return errorService.insertCDealError(cDealError);
    }


    //钱包密钥加密
    public String encodeHMAC(Map<String, Object> data, String walletCheckKey) {
        if (data == null || data.isEmpty()) {
            throw new IllegalArgumentException("Data cannot be empty.");
        }

        // Sort data by key
        Map<String, Object> sortedData = new TreeMap<>(data);

        StringBuilder str = new StringBuilder();
        for (Map.Entry<String, Object> entry : sortedData.entrySet()) {
            str.append("&").append(entry.getKey()).append("=").append(entry.getValue());
        }
        str.deleteCharAt(0);  // Remove the leading "&"
        str.append("&key=").append(walletCheckKey);
//        System.out.println("每一次加密------" + str);
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            byte[] hash = md.digest(str.toString().getBytes());

            // Convert the byte array to a hexadecimal string
            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(0xFF & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            return hexString.toString().toUpperCase();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    //构建Map
    public Map<String, Object> buildWalletInfoMap(CWalletPerson cWalletPerson) {
        Map<String, Object> walletData = new HashMap<>();
        walletData.put("user_uuid", cWalletPerson.getUserId());
        walletData.put("wallet_income", cWalletPerson.getWalletIncome());
        walletData.put("wallet_outcome", cWalletPerson.getWalletOutcome());
        walletData.put("balance_fee", cWalletPerson.getWalletFree());
        walletData.put("check_sign", cWalletPerson.getWalletSign());
        logger.debug("=============构建map通过=============");
        return walletData;
    }

    //构建Map
    public Map<String, Object> buildCompanyWalletInfoMap(CWalletCompany cWalletCompany) {
        Map<String, Object> walletData = new HashMap<>();
        walletData.put("user_uuid", cWalletCompany.getWalletPersonId());
        walletData.put("wallet_income", cWalletCompany.getWalletIncome());
        walletData.put("wallet_outcome", cWalletCompany.getWalletOutcome());
        walletData.put("balance_fee", cWalletCompany.getWalletFree());
        walletData.put("check_sign", cWalletCompany.getWalletSign());
        logger.debug("=============构建map通过=============");
        return walletData;
    }

    /**
     * 个人钱包充值
     *
     * @param userId
     * @param money
     * @return
     */
    public AjaxResult rechargePersonWallet(Integer userId, Integer money) {
        Assert.notNull(userId, "被绑定用户id不能为空");
        Assert.notNull(money, "充值金额不能为空");
        Assert.isTrue(money > 0, "充值金额必须大于0");

        logger.debug("=============校验参数通过=============");
        CUser cUser = userService.selectCUserByUserId(userId);
        CWalletPerson cWalletPerson = walletPersonService.selectCWalletPersonByUserId(userId);
        Assert.notNull(cUser, "用户不存在");
        Assert.notNull(cWalletPerson, "用户钱包不存在");


        Long balance = rechargeWallet("vip", money);
        System.out.println("balance: " + balance);
        //更新钱包
        updatePersonWallet(userId, balance);


        Map<String, Object> walletData = walletService.buildWalletInfoMap(cWalletPerson);
//        System.out.println("walletData: " + walletData);
        CWalletPerson walletPersonLater = walletPersonService.selectCWalletPersonByUserId(userId);
        if (!walletService.walletSignCheck(walletData)) {
            logger.debug("=============sign异常=============");
            //存入异常表
            walletService.saveError(walletData, cWalletPerson, walletPersonLater);
        }
        //更新签名
        Map<String, Object> walletData1 = walletService.buildWalletInfoMap(walletPersonLater);
//        System.out.println("walletData1: " + walletData1);
        logger.debug("=============更新签名=============");
        walletService.updateSign(walletData1);

        //添加个人流水记录
        CDealPerson cDealPerson = new CDealPerson();
        cDealPerson.setUserId(cUser.getUserId());
        cDealPerson.setDealType(1);
        cDealPerson.setDealOriginalJson(serialize(cWalletPerson));
        cDealPerson.setDealDisposeJson(serialize(walletPersonLater));
        cDealPerson.setDealAmount(balance);
        dealPersonService.insertCDealPerson(cDealPerson);

        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("msg", "您已成功充值" + balance + "kg");
        logger.debug("=============充值成功通过=============");
        return ajaxResult;
    }

    /**
     * 个人钱包消费
     *
     * @param userId
     * @param free
     * @return
     */
    public AjaxResult expensePersonWallet(Integer userId, Long free) {
        Assert.notNull(userId, "被绑定用户id不能为空");
        Assert.notNull(free, "消费金额不能为空");
        Assert.isTrue(free > 0, "消费金额必须小于于0");

        logger.debug("=============校验参数通过=============");
        CUser cUser = userService.selectCUserByUserId(userId);
        CWalletPerson cWalletPerson = walletPersonService.selectCWalletPersonByUserId(userId);
        Assert.notNull(cUser, "用户不存在");
        Assert.notNull(cWalletPerson, "用户钱包不存在");

        //封装更新前的信息
        Map<String, Object> walletData = walletService.buildWalletInfoMap(cWalletPerson);
        //更新钱包
        updateFillPersonWallet(userId, free);
//        System.out.println("cWalletPerson更新前信息: " + cWalletPerson);
        CWalletPerson walletPersonLater = walletPersonService.selectCWalletPersonByUserId(userId);
        if (!walletService.walletSignCheck(walletData)) {
            logger.debug("=============sign异常=============");
            //存入异常表
            walletService.saveError(walletData, cWalletPerson, walletPersonLater);
        }

        //封装更新后的信息
        Map<String, Object> walletData1 = walletService.buildWalletInfoMap(walletPersonLater);
//        System.out.println("cWalletPerson更新后信息: " + walletData1);
        //更新签名
        logger.debug("=============更新签名=============");
        walletService.updateSign(walletData1);

        //添加个人钱包流水记录
        CDealPerson cDealPerson = new CDealPerson();
        cDealPerson.setUserId(cUser.getUserId());
        cDealPerson.setDealType(2);
        cDealPerson.setDealOriginalJson(serialize(cWalletPerson));
        cDealPerson.setDealDisposeJson(serialize(walletPersonLater));
        cDealPerson.setDealAmount(free);
        dealPersonService.insertCDealPerson(cDealPerson);

        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("code", 200);
        ajaxResult.put("msg", "您已成功消费");
        ajaxResult.put("data", free);
        ajaxResult.put("cDealPersonId", cDealPerson.getDealRecordId());
        logger.debug("=============消费成功通过=============");
        return ajaxResult;
    }

    /**
     * 公司钱包充值
     *
     * @param personId
     * @param free
     * @return
     */
    public AjaxResult rechargeCompanyWallet(Integer personId, Long free) {
        Assert.notNull(personId, "被绑定公司id不能为空");
        Assert.notNull(free, "充值金额不能为空");
        Assert.isTrue(free > 0, "充值金额必须大于0");

        logger.debug("=============校验参数通过=============");
        CCompany cCompany = companyService.selectCCompanyByCompanyId(personId);
        CWalletCompany cWalletCompany = walletCompanyService.selectCWalletCompanyByWalletPersonId(personId);
        Assert.notNull(cCompany, "公司不存在");
        Assert.notNull(cWalletCompany, "公司钱包不存在");

        //更新钱包
        updateCompanyWallet(personId, free);

        //封装更新前的信息
        Map<String, Object> walletData = walletService.buildCompanyWalletInfoMap(cWalletCompany);
        CWalletCompany walletCompanyLater = walletCompanyService.selectCWalletCompanyByWalletPersonId(personId);
        if (!walletService.walletSignCheck(walletData)) {
            logger.debug("=============sign异常=============");
            //存入异常表
            walletService.saveCompanError(walletData, cWalletCompany, walletCompanyLater);
        }

        //封装更新后的信息
        Map<String, Object> walletData1 = walletService.buildCompanyWalletInfoMap(walletCompanyLater);

        logger.debug("=============更新签名=============");
        walletService.updateCompanySign(walletData1);


        //添加公司钱包流水记录
        CDealCompany cDealCompany = new CDealCompany();
        cDealCompany.setCompanyId(cCompany.getCompanyId());
        cDealCompany.setDealType(1);
        cDealCompany.setDealOriginalJson(serialize(cWalletCompany));
        cDealCompany.setDealDisposeJson(serialize(walletCompanyLater));
        cDealCompany.setDealAmount(free);
        dealCompanyService.insertCDealCompany(cDealCompany);

        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("msg", "您已成功充值" + free + "kg");
        logger.debug("=============充值成功通过=============");
        return ajaxResult;
    }

    /**
     * 公司钱包消费
     *
     * @param companyId
     * @param free
     * @return
     */
    @Override
    public AjaxResult expenseCompanyWallet(Integer companyId, Long free) {
        Assert.notNull(companyId, "被绑定用户id不能为空");
        Assert.notNull(free, "消费金额不能为空");
        Assert.isTrue(free > 0, "消费金额必须大于0");

        logger.debug("=============校验参数通过=============");
        CCompany cUser = companyService.selectCCompanyByCompanyId(companyId);
        CWalletCompany cWalletCompany = walletCompanyService.selectCWalletCompanyByWalletPersonId(companyId);
        Assert.notNull(cUser, "用户不存在");
        Assert.notNull(cWalletCompany, "用户钱包不存在");

        //封装更新前的信息
        Map<String, Object> walletData = walletService.buildCompanyWalletInfoMap(cWalletCompany);

        logger.debug("-------加注更新前的钱包信息 ->", cWalletCompany);
        System.out.println("-------加注更新前的钱包信息 ->" + cWalletCompany);

        //添加个人钱包流水记录
        CDealCompany cDealCompany = new CDealCompany();
        cDealCompany.setCompanyId(cUser.getCompanyId());
        cDealCompany.setDealType(2);
        cDealCompany.setDealOriginalJson(serialize(cWalletCompany));
        cDealCompany.setDealDisposeJson("");
        cDealCompany.setDealAmount(free);
        dealCompanyService.insertCDealCompany(cDealCompany);
        //更新钱包(不管出不出现异常都要更新)
        updateFillCompanyWallet(companyId, free);
        //查询更新后的信息
        CWalletCompany walletPersonLater = walletCompanyService.selectCWalletCompanyByWalletPersonId(companyId);
        logger.debug("-------加注更新后的钱包信息 ->", walletPersonLater);
        System.out.println("-------加注更新后的钱包信息 ->" + walletPersonLater);

        if (!walletService.walletSignCheck(walletData)) {
            logger.debug("=============sign异常=============");
            //存入异常表
            walletService.saveErrorCompany(walletData, cWalletCompany, walletPersonLater);
        }

        //封装更新后的信息
        Map<String, Object> walletData1 = walletService.buildCompanyWalletInfoMap(walletPersonLater);
        //更新签名
        logger.debug("=============更新签名=============");
        walletService.updateCompanySign(walletData1);

        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("code", 200);
        ajaxResult.put("msg", "您已成功消费");
        ajaxResult.put("data", free);
        ajaxResult.put("cDealCompanyId", cDealCompany.getDealRecordId());
        logger.debug("=============消费成功通过=============");
        return ajaxResult;
    }


    //充值更新钱包(个人)
    public int updatePersonWallet(Integer userId, Long money) {
        CWalletPerson cWalletPerson = walletPersonService.selectCWalletPersonByUserId(userId);
        cWalletPerson.setWalletFree(cWalletPerson.getWalletFree() + money);
        cWalletPerson.setWalletIncome(cWalletPerson.getWalletIncome() + money);
        return walletPersonService.updateCWalletPerson(cWalletPerson);
    }


    //加注更新钱包(个人)
    public int updateFillPersonWallet(Integer userId, Long money) {
        CWalletPerson cWalletPerson = walletPersonService.selectCWalletPersonByUserId(userId);
        cWalletPerson.setWalletFree(cWalletPerson.getWalletFree() - money);
        cWalletPerson.setWalletOutcome(cWalletPerson.getWalletOutcome() + money);
        return walletPersonService.updateCWalletPerson(cWalletPerson);
    }

    //充值更新钱包(公司)
    public int updateCompanyWallet(Integer personId, Long free) {
        CWalletCompany cWalletCompany = walletCompanyService.selectCWalletCompanyByWalletPersonId(personId);
        cWalletCompany.setWalletFree(cWalletCompany.getWalletFree() + free);
        cWalletCompany.setWalletIncome(cWalletCompany.getWalletIncome() + free);
        return walletCompanyService.updateCWalletCompany(cWalletCompany);
    }

    //加注更新钱包(公司)
    public int updateFillCompanyWallet(Integer companyId, Long free) {
        CWalletCompany walletCompany = walletCompanyService.selectCWalletCompanyByWalletPersonId(companyId);
        walletCompany.setWalletFree(walletCompany.getWalletFree() - free);
        System.out.println("更新钱包后计算余额:" + (walletCompany.getWalletFree() - free) + " free:" + free);
        walletCompany.setWalletOutcome(walletCompany.getWalletOutcome() + free);
        return walletCompanyService.updateCWalletCompany(walletCompany);
    }


    //充值计算钱包中余量
    public Long rechargeWallet(String type, Integer money) {
        CUnitPrice cUnitPrice = new CUnitPrice();
        List<CUnitPrice> unitPrices = unitPriceService.selectCUnitPriceList(cUnitPrice);

        Integer unitPrice = 0;

        for (CUnitPrice unitPriceEntry : unitPrices) {
            if (type.equalsIgnoreCase("temporary") && unitPriceEntry.getUnitTemporary() != null) {
                unitPrice = unitPriceEntry.getUnitTemporary();
                break;
            } else if (type.equalsIgnoreCase("vip") && unitPriceEntry.getUnitVip() != null) {
                unitPrice = unitPriceEntry.getUnitVip();
                break;
            }
        }
        System.out.println("unitPrice" + unitPrice + "money" + money);

        //计算余额
        double balance = (double) money / unitPrice;
        balance = Math.round(balance * 100.0) / 100.0;
        Long balanceLong = (long) (balance * 1000);

        return balanceLong;
    }

    //向微信回复
    public void responseToWeixin(HttpServletResponse response, String xml) {
        response.setContentType("text/xml;charset=utf-8");
        Map<String, String> stringStringMap = new HashMap<>();
        Map<String, String> result = new HashMap<>();
        if (!Objects.equals(xml, "")) {
            stringStringMap = WxPayKit.xmlToMap(xml);

            if (stringStringMap.get("result_code").equals("SUCCESS")) {
                result.put("return_code", "SUCCESS");
                result.put("return_msg", "OK");
                xml = WxPayKit.toXml(result);
                try {
                    response.getWriter().write(xml);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                result.put("return_code", "FAIL");
                result.put("return_msg", "");
                xml = WxPayKit.toXml(result);
                try {
                    response.getWriter().write(xml);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    // 后台通知
    public AjaxResult payNotice(String xml) {
        long start = System.currentTimeMillis();
        Map<String, String> stringStringMap = WxPayKit.xmlToMap(xml);
        String out_trade_no = stringStringMap.get("out_trade_no");
        logger.info("订单号：" + out_trade_no);
        String openId = stringStringMap.get("openid");
        int total_fee = Integer.parseInt(stringStringMap.get("total_fee"));
        //根据openid查找用户
        CUser user = new CUser();
        user.setOpenid(openId);
        List<CUser> cUsers = userService.selectCUserList(user);
        CUser cUser = new CUser();
        if (!cUsers.isEmpty()) {
            cUser = cUsers.get(0);
        } else {
            return AjaxResult.success("用户不存在");
        }

        //微信扫描
        if (out_trade_no != null && out_trade_no != "") {
            String[] order = out_trade_no.split("_");
            long balance = rechargeWallet("vip", total_fee);
            //更新钱包操作
            rechargePersonWallet(cUser.getUserId(), Integer.valueOf(total_fee));
            //添加订单到数据库
            COrder cOrder = new COrder();
            cOrder.setCompanyId(0);
            cOrder.setTargetUserId(cUser.getUserId());
            cOrder.setOrderAmount(balance);
            cOrder.setOrderMoney(total_fee);
            cOrder.setOrderPay(total_fee);
            cOrder.setOrderRefund(0);
            cOrder.setOrderNum(order[0]);
            cOrder.setDealType(1);
            cOrder.setOrderStatus(0);
            cOrder.setDealAmount(Math.toIntExact(balance));
            int i = orderService.insertCOrder(cOrder);
            Assert.isTrue(i > 0, "添加订单失败");
            long end = System.currentTimeMillis() - start;
            logger.warn("接口响应时间:" + end);
            return AjaxResult.success("充值成功");
        }
        return AjaxResult.success("添加订单信息失败");
    }

    @Override
    public AjaxResult refund(String orderNum, Integer refundFee) {
        //查询订单
        COrder cOrder = new COrder();
        cOrder.setOrderNum(orderNum);
        List<COrder> cOrders = orderService.selectCOrderList(cOrder);
        if (cOrders.isEmpty()) {
            return AjaxResult.error("订单不存在");
        }
        COrder Order = cOrders.get(0);
        //查询用户
        CUser cUser = userService.selectCUserByUserId(Order.getTargetUserId());
        if (cUser == null) {
            return AjaxResult.error("用户不存在");
        }
        //查询钱包
        CWalletPerson cWalletPerson = walletPersonService.selectCWalletPersonByUserId(cUser.getUserId());
        if (cWalletPerson == null) {
            return AjaxResult.error("钱包不存在");
        }

        JsApiOrderModel jsApiOrderModel = new JsApiOrderModel();
        jsApiOrderModel.setOut_trade_no(orderNum);
        jsApiOrderModel.setRefund_fee(refundFee.toString());
        jsApiOrderModel.setOut_refund_no(OrderNumberGenerator.generateOrderNumber());
        jsApiOrderModel.setTotal_fee(Order.getOrderMoney().toString());
        jsApiOrderModel.setNotify_url(wxConfig.getNotifyUrl());
        logger.info("jsApiOrderModel: " + jsApiOrderModel);

        AjaxResult ajaxResult = refundService.processRefund(orderNum, Order.getOrderMoney(), refundFee);
        return AjaxResult.success(ajaxResult);
    }


    public int updateCompanySign(Map<String, Object> walletInfo) {
        logger.debug("=============进入更新签名=============");
        String walletCheckKey = wxConfig.getWalletCheckKey();
        walletInfo.remove("check_sign");
        String checkSign = encodeHMAC(walletInfo, walletCheckKey);

        CWalletCompany cWalletCompany = new CWalletCompany();
        cWalletCompany.setWalletPersonId(Integer.parseInt(walletInfo.get("user_uuid").toString()));
        cWalletCompany.setWalletSign(checkSign);
        logger.debug("=============通过更新签名=============");
        return cWalletCompanyMapper.updateCWalletCompany(cWalletCompany);
    }

    //存入异常表(公司)
    public int saveCompanError(Map<String, Object> walletInfo, CWalletCompany cWalletCompanyFirst, CWalletCompany cWalletCompanyLater) {
        CDealError cDealError = new CDealError();
        cDealError.setUserId(Integer.parseInt(walletInfo.get("user_uuid").toString()));
        cDealError.setErrorFrom(1);
        cDealError.setDealAmount(Long.parseLong(walletInfo.get("wallet_income").toString()));
        cDealError.setDealType(1);
        cDealError.setDealOriginalJson(JsonUtils.serialize(cWalletCompanyFirst));
        cDealError.setDealDisposeJson(JsonUtils.serialize(cWalletCompanyLater));
        logger.debug("=============存入异常表通过=============");
        return errorService.insertCDealError(cDealError);
    }


}
